package com.anzia.stream;

import java.io.BufferedInputStream;
import java.io.FileInputStream;

/**
 *@ClassName com.anzia.stream.BufferedInputStream_Demo
 *@Description
 *@Author Anzia.
 *@Date 2021/4/9 13:06
 *@Version 1.0
 **/
public class BufferedInputStream_Demo {

    public static void main(String[] args) throws Exception {

        //创建BufferedInputStream
        FileInputStream fis = new FileInputStream("static\\test_in.txt");
        BufferedInputStream bis = new BufferedInputStream(fis);
        BufferedInputStream_Demo demo = new BufferedInputStream_Demo();

        //读取
        //demo.read_single(bis);
        demo.read_more(bis);

        //关闭
        bis.close();
        System.out.println();
        System.out.println("执行完毕");

    }

    public void read_single(BufferedInputStream bis) throws Exception {

        int data = 0;
        while ((data = bis.read()) != -1) {
            System.out.print((char) data);
        }

    }

    public void read_more(BufferedInputStream bis) throws Exception {

        byte[] bytes = new byte[1024];
        int count = 0;
        while ((count = bis.read(bytes)) != -1) {
            System.out.println(new String(bytes,0,count));
        }

    }

}
